<?php
$tag_slug = pods_url_variable('last');
$id = urldecode($tag_slug);

/* What we intend to do here is that get the last value of the url which is a tag. Then from the pod deal get the comma seperated list of tag values for each variable. Then check whether any of that value matches the tag obtained from the url. If it does then echo the detail page of the deal */
//$slug = substr($id, 2);
$tags = new Pod('tags',$id);
$tag_name = $tags->get_field('name');
?>
<div>
<h1 id="f_margin">Get <?php echo ucwords($tag_name); ?> Online</h1>
<?php buzzr_fb_like(); ?>
</div>
<div class="clear"></div>


<div class="brands_tabbed tabbed">
	<ul class="tabs">
		<li class="t1"><a class="t1 tab" title="Coupons">Coupons</a></li>
		<li class="t2"><a class="t2 tab" title="Offers">Offers</a></li>
		<li class="t3"><a class="t3 tab" title="Local Offers">Local Offers</a></li>
	</ul>
	<br/>
	<br/>
	<br/>
 	<div class="clear"></div>
 	
 	<div class="t1" id="t1">
  	
	  	<div class="views">
		  <a class="grid g-button">Grid View</a>
		  <a class="list g-button">List View</a>
		</div>
		<div class="clear"></div>
		<div id="list_wrap">
			<ul class="list">
			<?php
				$tagged_deals = new Pod('deal');
				$where = "tag_pick.slug='$id' && t.sale=0 && t.coupon=1 && t.camp_end > ".fix_date();
				$tagged_deals->findRecords("t.camp_start DESC", -1, $where);
				echo $tagged_deals->showTemplate('list_grid');
		  	?>
			</ul>
		</div>
		<div class="clear"></div>
		<div>
			<?php echo $tagged_deals->getPagination(); ?>
		</div>
	
	</div>
	<div class="t2" id="t2">
	<div class="views">
	  <a class="grid g-button">Grid View</a>
	  <a class="list g-button">List View</a>
	</div>
	<div class="clear"></div>
		<div id="list_wrap">
			<ul class="list">
			<?php
				$tagged_deals = new Pod('deal');
				$where1 = "tag_pick.slug='$id' && t.sale='0' && t.coupon='0' && t.camp_end > ".fix_date()." && t.camp_start <= ".fix_date();
				$tagged_deals->findRecords("t.camp_start DESC", -1, $where1);
				echo $tagged_deals->showTemplate('list_grid');
		  	?>
			</ul>
		</div>
		<div class="clear"></div>
		<div>
			<?php echo $tagged_deals->getPagination(); ?>
		</div>
		
	</div>
  
	<div class="t3" id="t3"> 
	<div class="views">
	  <a class="grid g-button">Grid View</a>
	  <a class="list g-button">List View</a>
	</div>
	<div class="clear"></div>
	<div id="list_wrap">
		<ul class="list">
		<?php
			$tagged_deals = new Pod('deal');
			$where2 = "tag_pick.slug='$id' && t.sale='1' && t.coupon='0' && t.camp_end > ".fix_date()." && t.camp_start <= ".fix_date();
			$tagged_deals->findRecords("id DESC", 15, $where2);
			echo $tagged_deals->showTemplate('list_grid');
	  	?>
		</ul>
	</div>
	</div>
  </div>